PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a problem with a php script that uploads 3 images to a upload directory and stores the image path to mysql database, i found the upload script on a forum, but it seems is not working. here is the script:
Html Form:
1. Use absolute paths
2. You can't use move_uploaded_file() to move more than one file at a time.
3. This: $_FILES['picture1'] ['picture2'] ['picture3'] is absolutely wrong. You need a little read about PHP syntax
There are 10 types of people in this world, those who understand binary and those who don't
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";
///////////////////////////////////////////////////////
// Use this code to display the error or success.
$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];
if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "We have recieved your files";
}
else {
echo "ERROR.....";
}
//////////////////////////////////////////////
// What files that have a problem? (if found)
if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}
if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}
if($filesize3==0) {
echo "There're something error in your third file";
echo "<BR />";
}
?>
So ... Let's clarify the upload part of the script:
1.
VladSun wrote:Use absolute paths
2.
VladSun wrote:don't use $HTTP_POST_FILES, use $_FILES instead
3. use move_uploaded_file() instead of copy() function
4. did you read the links I googled for you? There are some very useful and almost (because it's walways "almost") secure file upload scripts - I would recommend http://www.scanit.be/uploads/php-file-upload.pdf
So, fix these issues and let us continue to the DB part.
There are 10 types of people in this world, those who understand binary and those who don't
what would be my absolute path if I use xamp... C:\xampp\htdocs\eurolevel\apartamente ' where apartamente is my upload directory and eurolevel the directory with upload script
okay i have changed $HTTP_POST_FILES with $_FILES and also i have changed copy with move_uploaded_file()
I have read that PDF and i will make the changes to my script for prevent hacking.. thanks a lot for helping me! but now please let's go to database part, because i am very curios about it