Jump to content

problem copying files using a loop


lifeson2112

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.