Jump to content
php.lv forumi

datu ievadīšana un augšupielāde


ziedinjsh

Recommended Posts

Tā tad, šāds ir kods:

<?php
include "../misc/db.php";

if(isset($_POST['add'])){

$author = strip_tags($_POST['author']);
$title = strip_tags($_POST['title']);
$discription = strip_tags($_POST['discription']);
$date = date("j, n, Y");

$cover_folder = "../cover/";
$cover_path = $cover_folder . basename($_FILES['cover']['name']);
$cover = basename($_FILES['cover']['name']);

$audio_folder = "../mp3/";
$audio_path = $audio_folder . basename($_FILES['audio']['name']);
$audio = basename($_FILES['audio']['name']);



$relese = mysql_query("INSERT INTO relise (author, title, discription, date, cover, audio) VALUES ('$author', '$title', '$discription', '$date', '$cover', '$audio') ");
move_uploaded_file($_FILES['cover']['tmp_name'], $cover_folder);
move_uploaded_file($_FILES['audio']['tmp_name'], $audio_folder);
echo "Done!";


}


?>

<form method='post' action='add.php'>
Author:<input type ='text' name='author'>
Title:<input type='text' name='title'>
Discription:<input type='text' name='discription'>
Cover:<input type='file' name='cover'>
Audio:<input type='file' name='audio'>

<input type='submit' name='add' value='Add'>
</form>

 

Nospiežod pogu add notiek sekojošas lietas.

 

Pirmkārt jau izlec notices:

Notice: Undefined index: cover in D:\WEB\www\r\admin\add.php on line 12

 

Notice: Undefined index: cover in D:\WEB\www\r\admin\add.php on line 13

 

Notice: Undefined index: audio in D:\WEB\www\r\admin\add.php on line 16

 

Notice: Undefined index: audio in D:\WEB\www\r\admin\add.php on line 17

 

Notice: Undefined index: cover in D:\WEB\www\r\admin\add.php on line 22

 

Notice: Undefined index: audio in D:\WEB\www\r\admin\add.php on line 23

 

bet tas nu tā, galvenais ir tas, ka author, title, description ievadās iekš mysql, bet cover un audio neievadās un faili neaugšupielādējas, kas par vainu?

 

Paldies jau iepriekš! :)

Link to comment
Share on other sites

ieliku

<?php
include "../misc/db.php";

if(isset($_POST['add'])){

$author = strip_tags($_POST['author']);
$title = strip_tags($_POST['title']);
$discription = strip_tags($_POST['discription']);
$date = date("j, n, Y");

$cover_folder = "../cover/";
$cover_path = $cover_folder . basename($_FILES['cover']['name']);
$cover = basename($_FILES['cover']['name']);

$audio_folder = "../audio/";
$audio_path = $audio_folder . basename($_FILES['audio']['name']);
$audio = basename($_FILES['audio']['name']);



$relese = mysql_query("INSERT INTO relise (author, title, discription, date, cover, audio) VALUES ('$author', '$title', '$discription', '$date', '$cover', '$audio') ");
move_uploaded_file($_FILES['cover']['tmp_name'], $cover_folder);
move_uploaded_file($_FILES['audio']['tmp_name'], $audio_folder);
echo "Done!";

print_r($_POST);

}


?>

<form action='add.php' method='post' enctype='multipart/form-data'>
Author:<input type ='text' name='author'>
Title:<input type='text' name='title'>
Discription:<input type='text' name='discription'>
Cover:<input type='file' name='cover'>
Audio:<input type='file' name='audio'>

<input type='submit' name='add' value='Add'>
</form>

 

pazuda notices, bet nu pārējais bez izmaiņām un tagad vairs ziņa echo "Done!"; neparādās

Link to comment
Share on other sites

Ja Tev if izpildās, tad iespējams nenostrādā vaicājums vai arī move_uploaded_file(), paskaties vai tagad datubāzē parādās ieraksts, kad esi izlabojis formai enctype='multipart/form-data'? Būtībā ja šīs vietas nestrādātu, tad laikam izvadītos kļūdu paziņojumi, iespējams ka tomēr ceļš uz augšupielādes direktorijām nav pareizi norādīts.

Link to comment
Share on other sites

viņš ievad datus, bet pie cover un audio viņš ieliek bildes nosaukumu un failus neaugšupielādē!

 

kapēc pie audi viņš ieliek to pašu ko pie bildes un nav faila precīzs links piem. kā: cover/image.jpg? parāda tikai image.jpg un pie audio tas pats, kapēc viņš audio nenolasa? :?

 

Tagad vispār viņš neko neievada.. neparādās neviens errors, nekas.

 

 

Tasir sviests.. izmet warningus:

 

Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in D:\WEB\www\r\admin\add.php on line 19

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\WEB\tmp\php5437.tmp' to 'cover/' in D:\WEB\www\r\admin\add.php on line 19

 

Tas nozīmē ka vajag pilnu direktoriju, bet man ir tads pats kods citur un viņš visu izdara!!

Edited by ziedinjsh
Link to comment
Share on other sites

<?php
error_reporting(E_ALL);
include "../misc/db.php";

if(isset($_POST['add'])){

$author = strip_tags($_POST['author']);
$title = strip_tags($_POST['title']);
$discription = strip_tags($_POST['discription']);
$date = date("j, n, Y");

$cover_dir = "../cover/";
$cover_path = $cover_dir . basename($_FILES['cover']['name']);
$cover = basename($_FILES['cover']['name']);



move_uploaded_file($_FILES['cover']['tmp_name'], $cover_path);


$relise = mysql_query("INSERT INTO relise (author, title, discription, date, cover, audio) VALUES ('$author', '$title', '$discription', '$date', '$cover', '$audio') ");
echo "Done!";



}


?>

<form action='add.php' method='post' enctype='multipart/form-data'>
Author:<input type ='text' name='author'>
Title:<input type='text' name='title'>
Discription:<input type='text' name='discription'>
Cover:<input type='file' name='cover'>



<input type='submit' name='add' value='Add'>
</form>

 

tagad iet.. vismaz cover, bet kad pielieku viasu topašu arī audio, tad audio nepievienojas

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...