kyleldi Posted October 4, 2007 Share Posted October 4, 2007 I keep getting an error when I try to execute my upload script, does anyone see what i've got wrong? It's supposed to pull the $name field and create a folder (using _ instead of spaces), and then copy those files into that folder and replace those spaces w/ underscores as well. Error: Warning: copy(files/Customer_Name/keyboard.jpg) [function.copy]: failed to open stream: No such file or directory in submitquote.php on line 60 else{ $dirname = str_replace(" ","_",$name); if(!file_exists($dirname)) mkdir($dirname, 0755); $image_list[14] = str_replace(" ","_",$image_list[14]); $image_part = date("")."".$HTTP_POST_FILES['file01']['name']; $image_list[14] = $image_part; copy($HTTP_POST_FILES['file01']['tmp_name'], "files/$dirname/".$image_part); // the above line is line 60 // $image_part = date("")."".$HTTP_POST_FILES['file02']['name']; $image_list[15] = $image_part; copy($HTTP_POST_FILES['file02']['tmp_name'], "files/$dirname/".$image_part); $image_part = date("")."".$HTTP_POST_FILES['file03']['name']; $image_list[16] = $image_part; copy($HTTP_POST_FILES['file03']['tmp_name'], "files/$dirname/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/ Share on other sites More sharing options...
micah1701 Posted October 4, 2007 Share Posted October 4, 2007 are you sure you have the correct path to the file? is "files" a folder within the directory that the script is running in? or is it in the root of your website? should it be copy("/files/Customer_Name/keyboard.jpg") ? or perhaps the full path: copy("/var/html/home/some_other_directory/files/Customer_Name/keyboard.jpg") ? I'd mess around with that first Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/#findComment-361707 Share on other sites More sharing options...
kyleldi Posted October 4, 2007 Author Share Posted October 4, 2007 files is a folder within the directory of the php file that's giving the error. The script itself didn't used to create a folder or anything, and it always worked just fine- so I'm assuming that the path is fine. Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/#findComment-361720 Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 Let's say this script is in the folder wwwroot. mkdir($dirname, 0755); That will create the directory 'wwwroot/dirname/'. copy($HTTP_POST_FILES['file01']['tmp_name'], "files/$dirname/".$image_part); That will try to copy a file into 'wwwroot/files/dirname'. Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/#findComment-361725 Share on other sites More sharing options...
kyleldi Posted October 4, 2007 Author Share Posted October 4, 2007 That's what it's supposed to do- it's just giving me the failed to open stream error. Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/#findComment-361727 Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 Not according to your OP. It's supposed to pull the $name field and create a folder (using _ instead of spaces), and then copy those files into that folder and replace those spaces w/ underscores as well. You seem to want to create folder X, then put a file in folder X. What you're actually doing is creating folder X and trying to put a file in folder Y. You need to change either one of the two lines of code I quoted above to fix the problem. Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/#findComment-361744 Share on other sites More sharing options...
kyleldi Posted October 4, 2007 Author Share Posted October 4, 2007 Ok, I took care of the file path problem, but for some reason it still won't replace the spaces in each filename with underscores. Here's my code to make it easier to understand... Thanks! $file01 = str_replace(" ","_",$$file01); $file02 = str_replace(" ","_",$$file02); $file03 = str_replace(" ","_",$$file03); if($HTTP_POST_FILES['file01']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['file01']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['file01']['name'].", was not uploaded!"; $errors=1; } if($HTTP_POST_FILES['file02']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['file02']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['file02']['name'].", was not uploaded!"; $errors=1; } if($HTTP_POST_FILES['file03']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['file03']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['file03']['name'].", was not uploaded!"; $errors=1; } if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email)){ $error.="<li>Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $dirname = str_replace(" ","_",$name); if(!file_exists($dirname)) mkdir($dirname, 0755); $image_part = date("")."".$HTTP_POST_FILES['file01']['name']; $image_list[14] = $image_part; copy($HTTP_POST_FILES['file01']['tmp_name'], "$dirname/".$image_part); $image_part = date("")."".$HTTP_POST_FILES['file02']['name']; $image_list[15] = $image_part; copy($HTTP_POST_FILES['file02']['tmp_name'], "$dirname/".$image_part); $image_part = date("")."".$HTTP_POST_FILES['file03']['name']; $image_list[16] = $image_part; copy($HTTP_POST_FILES['file03']['tmp_name'], "$dirname/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); Quote Link to comment https://forums.phpfreaks.com/topic/71819-help-with-an-error/#findComment-361768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.