473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Problem with script to save images from multiple urls to local folder

You enter urls' into a text area on another page, when you click submit these urls get loaded into an array. The for loop should work through every element in the array, saving each picture with its basename.

For some reason it will only save the first image. I have traced the issue to the file_put_contents(). As shown from my test echo's the names of the files are being assigned correctly, but the file_put_contents will not save more than one image.

Below is the code...


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.  $info = "";
  5.  if(isset($_POST['uploadfilepic'])){
  6.     $info = $_POST["com"];
  7.     $DIR = './images/products/';
  8.     $data = explode("\n", $info);
  9.  
  10.  
  11.     foreach($data as $hop){
  12.  
  13.     $imgName = basename($hop);
  14.     $filename = ($DIR . $imgName);
  15.  
  16.     $url = file_get_contents($hop);
  17.  
  18.  
  19.        if(!empty($url)){
  20.  
  21.            file_put_contents($filename, $url);
  22.  
  23.            Echo " Upload of " .$imgName." was a success! <br/><br/>";
  24.  
  25.  
  26.           }
  27.           else
  28.                 echo $imgName." Upload Failed";  
  29. }
  30.  
  31. }
  32.  
  33. ?>
The script will echo that all images have been uploaded, but only one will be saved into the folder. Thank you for all your help

Also this error is shown when you try and upload more than one url

Warning:
file_put_contents(./images/products/b9de9e86e4e55e12744975d05c1b93608bdeeb9537718e19b3 d0c7cbf93278b0_400_400.jpg ) [function.file-put-contents]: failed to open stream: Invalid argument in C:\wamp\www\catalog\imgcom.php on line 21
Jul 24 '12 #1
0 1434

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Jonathan Daugherty | last post by:
Does anyone here know if the wxImage class in wxPython supports dislaying images from URLs? -- Jonathan Daugherty http://www.cprogrammer.org "It's a book about a Spanish guy called Manual,...
1
by: Markus Wallner | last post by:
Hi! I want to replace images through URLs with the help of a regular expression. For example: <img src='http://xxxxx.net/photo/small.jpg'> should be replaced through: <a...
1
by: Kelly | last post by:
hi all, it's me again. i'm using ASP.NET Web Application, using a "File Field"component under HTML tab and i do a right click on the component and select "Run As Server Control". This was done...
26
by: Howard Brazee | last post by:
I would like to click on a URL of a html document that will open several URLs at once for me. Does someone have an example of a html document that will do this?
4
by: Yuri Vorontsov | last post by:
Hallo! We have troubles (post XP SP2) to open local folders from the web application: - the web application allows users to select a local file (input type=file) - the system DOES NOT upload...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
0
by: jason | last post by:
I googled a lot, couldn't find a good solution. Any help is greatly appreciated. What I want to do is: Given a web page in a running IE browser , i want to save an image in this web page to...
8
by: Mario Krsnic | last post by:
Hello and Merry Christmas! I flip in my card play some cards using the call "drawimage". These flipped cards are saved in temporary images on the server: temp1.jpg, temp2.jpg... Everything works...
4
by: krishna81m | last post by:
A very interesting problem for a simple requirement and not easily available solution: How would I create a button which will allow the user to specify where the file to be downloaded will be...
0
by: Jimis | last post by:
I need to validate XMLs files against XSDs. The XML will be downloaded from URL and I will keep it as StremReader or XmlDocument. The XSD will return from DataBase as nvarchar(max). I am prohibited...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.