lifeson2112 Posted June 28, 2007 Share Posted June 28, 2007 Hello, I have a spreadsheed with names and image urls that I have converted to a tab delimited text file. Column one has the product name and column two has a url to an image on another site. I am trying to loop through the file and copy the image onto my computer, but it is giving me this error: "Warning: copy(http://ec1.images-amazon.com/images/I/41Oj92a63gL._AA280_.jpg ) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\Program Files\xampp\htdocs\copy.php on line 16" here's some of the code. I have the problem area commented so you can get a better idea of what's wrong here: <?php $sourceFile=file("C:\Documents and Settings\Jared\My Documents\amazoninventory\amazon_pics.txt"); foreach($sourceFile as $row) { $rowArray=explode("\t",$row); //this will make the file name uploadable $nameNoEndSpace = preg_replace('/ $/',"","$rowArray[0]"); $ridArray=array(" ","'","/",",","#"); $replaceArray=array("-","-","-","",""); $imageName= str_replace($ridArray,$replaceArray,$nameNoEndSpace); $imageLocation="C:/Documents and Settings/Jared/My Documents/amazoninventory/images/"; //debugging lines echo"$rowArray[1]\n<br>"; echo"$imageLocation"."$imageName".".jpg"; /***************************************************************/ // PROBLEM AREA /***************************************************************/ //I have problems with the $rowArray[1] here. It works fine if I copy the url that gets outputted from the first debug line above, but this right here really screws things up. copy("$rowArray[1]","$imageLocation"."$imageName".".jpg"); } ?> so, I guess the problem here is reading the input file from an array. Does my version of php (4) just not allow it? again, this works fine if I enter a url directly instead of trying to read it from the array (which does provide an accurate url). any help will be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/ Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 your file path is invalid. Try making a form <input type="file"> for it. That or if you are running a server on your server such as apache move it to your htdocs folder and then rename it with its server address not its physical drive address Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-285044 Share on other sites More sharing options...
lifeson2112 Posted June 28, 2007 Author Share Posted June 28, 2007 I havent had any problems with the file paths if I just paste one from the text file, but the copy function won't read the file path correctly from an array. Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-285047 Share on other sites More sharing options...
lifeson2112 Posted June 28, 2007 Author Share Posted June 28, 2007 Is this some wierd security feature that php has? all I want to do is download a bunch of images from amazon. Again, the url's work fine when I manually paste them into the copy feature, but when I try to get the url from the array it gives me this error: "Warning: copy(http://ec1.images-amazon.com/images/I/41Bd98krbnL._AA280_.jpg ) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\Program Files\xampp\htdocs\copy.php on line 30" but when I paste the exact url (http://ec1.images-amazon.com/images/I/41Bd98krbnL._AA280_.jpg) into the copy function it works. I don't know what to do. I tried putting the array element into another variable before it hit the copy function but it still does the same thing. I also messed around with putting double and single quotes (and no quotes) around the rowArray[1]. I don't want to give up on this though because it would save a hell of a lot of time and the solution is right there... Anyone? should I find another fix to this problem? thanks Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-285069 Share on other sites More sharing options...
lifeson2112 Posted June 28, 2007 Author Share Posted June 28, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-285104 Share on other sites More sharing options...
lifeson2112 Posted June 28, 2007 Author Share Posted June 28, 2007 A simple "you can't do that, moron" would even suffice. It's consuming me and I need to know if anyone has a solution. If not, screw it. I'm almost there and the fix looks like it's so close it's about to bite my head off. One line, causing me countless days (or has it been hours?) of torture!! Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-285222 Share on other sites More sharing options...
lifeson2112 Posted June 29, 2007 Author Share Posted June 29, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-285545 Share on other sites More sharing options...
lifeson2112 Posted July 5, 2007 Author Share Posted July 5, 2007 bump Link to comment https://forums.phpfreaks.com/topic/57587-problem-copying-files-using-a-loop/#findComment-290476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.