Jump to content

File Upload Problem


azraelGG

Recommended Posts

i looked some tutorial how to upload files, and got some script i should use for that, but i cant set good values for my destination folder i guess

can you tell me where do i get things wrong

 

if(!empty($_FILES)){
   $tempFile = str_replace(" ", "", $_FILES['picUpload']['tmp_name']);
   $targetPath = $_SERVER['DOCUMENT_ROOT'].'/images/mehanizacija/';
   $broj = rand(100,999);
   $targetFile = str_replace(" ", "", $targetPath.$broj.'-'.$_FILES['picUpload']['name']);
   $linkPicture = str_replace(" ", "", "http://localhost/images/mehanizacija/".$broj.'-'.$_FILES['picUpload']['name']);
   move_uploaded_file($tempFile, $targetFile);
  }

 

Warning: move_uploaded_file(/home/azrael/htdocs/images/mehanizacija/408-pics01.jpg): failed to open stream: No such file or directory in /home/azrael/htdocs/agro/stroj.php on line 76

 

Warning: move_uploaded_file(): Unable to move '/tmp/phpKEpgr3' to '/home/azrael/htdocs/images/mehanizacija/408-pics01.jpg' in /home/azrael/htdocs/agro/stroj.php on line 76

 

line76

move_uploaded_file($tempFile, $targetFile);

 

i use submit button from form that have multiple forms so i need that if(!empty($_FILES))

and in $linkPicture can i also use $_SERVER['DOCUMENT_ROOT'] so if i send this to some server he will look in my root folder and not directly on link that i will need to change

Link to comment
https://forums.phpfreaks.com/topic/271867-file-upload-problem/
Share on other sites

Also, I wonder if you can explain why you're doing this?

 $tempFile = str_replace(" ", "", $_FILES['picUpload']['tmp_name']);

 

Not only is it quite unnecessary because the temp name never contains a space, but what would have happened if it did..? :P

Link to comment
https://forums.phpfreaks.com/topic/271867-file-upload-problem/#findComment-1398875
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.