Ok Basically i am following this guide which is pretty straight forward but, I am at the point now where i am completely lost. I don't want to have to start all over again and I hope it's just a minor adjustment but anyhow heres the error:
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /I don't want to publicize the path name/html/add.php on line 39
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpqd62Gk' to 'thumbnails/' in /I don't want to publicize the path name/add.php on line 39
Sorry, there was a problem uploading your cover. Please check it is the appropriate size and format.
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /I don't want to publicize the path name/add.php on line 52
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFVlGsv' to 'audio/' in /I don't want to publicize the path name/add.php on line 52
Sorry, there was a problem uploading your song. Please check it is the appropriate size and format.
And here is the "add.php" which is executed after submitting the form :
<?php
include "db_config.php";
//This is the directory where images will be saved
$targetp = "thumbnails/";
$targetp = $targetp . basename( $_FILES['cover']['artist']);
//This is our size condition
if ($uploaded_size > 100000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is the directory where songs will be saved
$targets = "audio/";
$targets = $targets . basename( $_FILES['song']['artist']);
//This is our size condition
if ($uploaded_size > 6000000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This gets all the other information from the form
$title=$_POST['title'];
$artist=$_POST['artist'];
$cover=($_FILES['cover']['artist']);
$song=($_FILES['song']['artist']);
$today = date("Ymd");
$ip = $_SERVER['REMOTE_ADDR'];
//Writes the information to the database
mysql_query("INSERT INTO `Thumbnails` VALUES ( '', '$artist - $title', '$cover', '', '$song', '$title', '$artist', '$today', '$ip')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['cover']['tmp_name'], $targetp))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['cover']['artist']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your cover. Please check it is the appropriate size and format.";
}
//Duplicate for song
if(move_uploaded_file($_FILES['song']['tmp_name'], $targets))
{
echo "The file ". basename( $_FILES['song']['artist']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your song. Please check it is the appropriate size and format.";
}
?>
Perhaps a step in the right direction would be greatly appreciated as it has gotten to the point where it all feels like scribble on a screen but, I'd hate to start all over again.
Try to
Change
basename( $_FILES['cover']['artist']);
To
basename( $_FILES['cover']['name']);
try
$targetp = "/thumbnails/;
$targets = "/audio/";
or specify full path name like c:/some/path/here
Related
There is no solution, as i have searched a lot on moving my uploaded image into directory here is my php code :
<?php
//Profile Image upload script
if (isset($_FILES['profilepic'])) {
if (((#$_FILES["profilepic"]["type"]=="image/jpeg") || (#$_FILES["profilepic"]["type"]=="image/png") || (#$_FILES["profilepic"]["type"]=="image/gif"))&&(#$_FILES["profilepic"]["size"] < 1048576)) //1 Megabyte
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
$dir = "userdata/profile_pics/$rand_dir_name";
mkdir($dir);
move_uploaded_file($_FILES["profilepic"]["tmp_name"],"userdata/profile_pics/$rand_dir_name".$_FILES["profilepic"]["name"]);
$profile_pic_name = $_FILES["profilepic"]["tmp_name"];
echo $profile_pic_name;
$profile_pic_query = mysqli_query($conn,"UPDATE users2 SET profile_pic='$rand_dir_name/$profile_pic_name' WHERE username='$user'");
}
else
{
$msg5 = "Invailid File! Your image must be no larger than 1MB and it must be either a .jpg, .jpeg, .png or .gif";
}
}
?>
but when I try to upload image,it creates the random folder in userdata/profile_pics but it doesn't move the file into random folder directory i have also created a custom php.ini file with file_uploads = On, but i recieve the following warning when i submit the form :-
Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in /home/rahulkapoor90/public_html/note.php on line 26
Warning: move_uploaded_file(): Unable to move '/tmp/phpO592dd' to 'userdata/profile_pics/zAGC9wOhVyoe3R5' in /home/rahulkapoor90/public_html/note.php on line 26
/tmp/phpO592dd
For anyone else who comes across this error, in my case it was a permissions issue. I re-factored some legacy code and checked the wrong directory for permissions and instead kept getting this misleading error message.
Wasted few hours to get the correct cause. You can try 2 things
Verify your destination folder
`$destdir="YOUR-COMPLETE-DESTINATION-FOLDER/uploads/";
if(is_dir($destdir) && is_writable($destdir))
{echo "<strong>UPLOAD DIRECTORY EXIST & WRITABLE</strong>";}
else
{echo "<strong>ISSUE WITH UPLOAD DIRECTORY</strong>";}`
Confirm 2nd parameter of move_uploaded_file is a file name NOT A DIRECTORY NAME
In my case this turned to be the issue
if(move_uploaded_file($tempname,"$destdir/".$_FILES['profilepic']['name']"))
{echo 'FILE UPLOADED SUCCESSFULLY';}
else
{echo "FAILED TO UPLOAD";}
I get following errors and I don't know why.
Notice: Undefined index: uploaded in C:\xampp\htdocs\site\upload.php on line 3
Notice: Undefined variable: uploaded_size in C:\xampp\htdocs\site\upload.php on line 7
Notice: Undefined variable: uploaded_type in C:\xampp\htdocs\site\upload.php on line 14
Notice: Undefined index: uploaded in C:\xampp\htdocs\site\upload.php on line 29
I tried to include the source of the php in this post but couldn't.
Here is link to pastebin: My source code
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
Edit 1 : I got the code from about.com about.com
1.) In your $FILES array, there's no uploaded index defined. Possibly because it's $_FILES That's the first one. Try
<pre>
print_r($FILES);
print_r($_FILES);
</pre>
to see what is in there.
2.) ¿Where are you initializing those variables being used in the conditionals? You must extract data from the file element in the array and assign it to the variables before using it.
The first notice is telling you that on this line:
$target = $target . basename( $_FILES['uploaded']['name']) ;
There is no 'uploaded' index into the $_FILES array because no file was uploaded in a form with the file input named uploaded.
The next notice is telling you that on this line:
if ($uploaded_size > 350000)
You are accessing a variable named $uploaded_size which has never previously been defined, so how could it possibly hold some value greater than 350000?
Same issue with the next two notices. You seem to be missing some code, and are testing code for handling uploaded files without uploading a file, or without using a form with the enctype and input names it expects.
If you find that the $_FILES array does not contain any reference to your uploaded file, make sure your form tag includes enctype="multipart/form-data".
I'm doing a simple file upload using the following script:
$errors = '';
$target_path = "[PATH HERE]";
$target_path = $target_path . basename($_FILES['uploadFile']['name']);
if(move_uploaded_file($_FILES['uploadFile']['tmp_name'], $target_path)) {
$errors = "The file ". basename( $_FILES['uploadFile']['name']). " has been uploaded";
} else{
$errors = "There was an error uploading the file, please try again! Type: " . $_FILES['uploadFile']['type'];
}
For some reason, I get an error uploading the file and the file type is not displayed. It seems to only grab the name of the file without the extension (i.e. "test" rather than "test.pdf"). I'm sure it's something simple, but what am I doing wrong?
If you check the error element in the files array, you'll probably find it's some value other than 0. The error should be 0 if nothing went wrong. Otherwise, compare the value stored in error against the PHP documentation to determine what went wrong.
Perhaps your entering the path wrong (ending slash), or php dont have permission to write to the directory.
<?php
error_reporting(E_ALL); // Show some errors
$target_path = "/var/www/somesite.com/uploads/"; // Would require a ending slash
$target_path = $target_path.basename($_FILES['uploadFile']['name']);
if(move_uploaded_file($_FILES['uploadFile']['tmp_name'], $target_path)) {
$errors = "The file ". basename( $_FILES['uploadFile']['name']). " has been uploaded";
} else{
$errors = "There was an error uploading the file, please try again! Type: " . $_FILES['uploadFile']['type'];
}
?>
ho everyone i am trying to upload images but i got a warning that i didn't understand
here is the code
// print out contents of $_FILES ARRAY
print "Print out of the array of files: FILES <br>";
print_r($_FILES);
print "<br><br>";
$F1 = $_FILES["fname"];
print_r($F1);
print "<br><br>";
// 0 means a successful transfer
if ($_FILES["fname"]["error"] > 0) {
print "An error occurred while uploading your file";
exit(0);
}
// only accept jpg images pjpeg is for Internet Explorer.. should be jpeg
if (!($_FILES["fname"]["type"] == "image/pjpeg")) {
print "I only accept jpg files!";
exit(0);
}
// divide size by 1024 to get it in KB
if ($_FILES["fname"]["size"] / 1024 > 50) {
print "Your gif file is too large! Less that 50KB please!";
exit(0);
}
// check that file is not already there in your uploads folder
if (file_exists("Uploads/" . $_FILES["fname"]["name"])) {
print "$F1[name] already exists. Choose another name for your file.";
exit(0);
}
// move file from temp location on server to your uploads folder
**move_uploaded_file($_FILES["fname"]["tmp_name"], "Uploads/".$_FILES["fname"]["name"]);**
print "Stored in:"." Uploads/".$_FILES["fname"]["name"];
// save location of upload to text file uploads.txt for later use
$datafile = fopen("uploads.txt","a");
flock($datafile,1);
fwrite($datafile, "Uploads/".$_FILES["fname"]["name"]."\n");
flock($datafile,3);
fclose($datafile);
and the warning is( refer to bold line)
Warning:
move_uploaded_file(Uploads/avatar3.jpg):
failed to open stream: No such file or
directory in
/home/www/mariam.awardspace.info/php/posts.php
on line 57
Warning: move_uploaded_file(): Unable
to move '/tmp/phprqcpQB' to
'Uploads/avatar3.jpg' in
/home/www/mariam.awardspace.info/php/posts.php
on line 57
thanks in advance
2 things come to mind.
Try using a path like
$_SERVER['DOCUMENT_ROOT'].'/path/to/file.jpg');
Then make sure the uploads folder exists in the root folder of your site
The directory "Uploads" does not exist or you don't have sufficient permissions to write to it.
Hi I am quite new to php but i have been following some tutorials but they don't seem to work so I have tried to adapt them.
I have tested this code and it works to a point but theres something else I can't get my head around, the php file is not uploading (fine) but the details are still being writen to the datbase although the $ok is spose to be set to 0 (not fine). It might be easier if explain what is ment to happen here:
-The User can upload gif or jpeg files. Details added to the db.
-The User can upload no file as a default will be used. Details added to the db.
-The User should not be able to upload any other file. No record should be on the db, user should have to try again.
My Code so far:
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
$ok=0;
//This gets all the other information from the form
$name= mysql_real_escape_string ($_POST['nameMember']);
$bandMember= mysql_real_escape_string ($_POST['bandMember']);
$pic= mysql_real_escape_string ($_FILES['photo']['name']);
$about= mysql_real_escape_string ($_POST['aboutMember']);
$bands= mysql_real_escape_string ($_POST['otherBands']);
$uploaded_size=$_FILES['photo']['file_size'];
if ($uploaded_size > 350000)
{
echo "Your file is too large, 35Kb is the largest file you can upload.<br>";
$ok=0;
}
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
if (!($uploaded_type =="image/jpeg"))
{
echo "JPEG<br>";$ok=1;
}
if ($uploaded_type =="image/gif")
{
echo "GIf<br>";$ok=1;
}
if (empty($pic)){
echo "You haven't uploaded a photo, a default will be used instead.<br/>";$ok=1;}
if ($ok==0)
{
Echo "Sorry your file was not uploaded, please try again with the correct format.";
}
//If everything is ok we try to upload it
else
{
// Connects to your Database
mysql_connect("localhost", "*******", "******") or die(mysql_error()) ;
mysql_select_db("project") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO dbProfile (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory<br/>";
print "<a class=\"blue\" href=\"createMember.php\">Add Another Record</a> | <a class=\"blue\" href=\"listMember.php\">Band Member Profiles and Affiliates Menu</a>";
}
else {
//Gives and error if its not
echo "<p>If you have uploaded a picture there may have been a problem uploading your file.</p>";
print "<a class=\"blue\" href=\"createMember.php\">Add Another Record</a> | <a class=\"blue\" href=\"listMember.php\">Band Member Profiles and Affiliates Menu</a>";
}
}
?>
Cheers in advance. CHL
The error probably is this if statement:
if (!($uploaded_type =="image/jpeg"))
{
echo "JPEG<br>";$ok=1;
}
Because every time you upload an image that does not have a content type that equals "image/jpeg", $ok evaluates to 1, so everything gets written to the database.
But also notice, that just checking the MIME type like this can get you into trouble, since the user is able to fake the MIME type of a file.
You could use Imagick to get the correct image MIME type, for example. See more details here: http://de2.php.net/manual/en/function.imagick-identifyimage.php
Edit: Just noticed, that $uploaded_type does not get initialized anywhere in your script. As I said, you can do a rough estimation of the MIME type by using $_FILES['photo']['type'].