View Full Version : trying to save files to server via a form

02-28-2008, 09:14 PM
i am trying to build a form where the user inputs an image from a weblink or an upload.

the form code is:

<form action="" method="post">
<p>You can either upload an icon or you can point us to a weblink. The jpeg, gif or png file will be resized to 25 x 25 pixels.</p>
<p>Weblink Pixel Icon: <input type="text" name="pixelURL" size="55" value="http://"></p>
<p>Upload Pixel Icon: <input type="hidden" name="MAX_FILE_SIZE" value="100000" /><input type="file" name="uploadpixelURL" size="44"></p>
<p>Step 2:</p>
<p>Now all you have to do is enter the web link you want the traffic to go to:</p>
<p>Destination: <input type="text" name="destinationURL" size="55" value="http://"></p>
<p><input type="image" name="confirmPixelBuy" src="http://www.foo.com/img/icons/icon_claimmypixels.gif"></p>

// user decided to upload a pixel using var $uploadpixelURL
$fileext = '.jpg';
$fileext = '.gif';
$newname = $_SESSION[userid].'_'.md5(rand(1,1000)).$fileext;
if(move_uploaded_file($_FILES['uploadpixelURL']['tmp_name'], $target_path)) {
echo "<p>There was an error uploading the file, please try again</p>";
copy($pixelURL, $target_path);
$filename = $_FILES['uploadpixelURL']['tmp_name'];
echo '<p>filename is:__ '.$filename.'</p>';
rename($filename, $newname);
$pixelURL = 'http://www.foo.com/img/pixelate/'.$newname;
echo '<p>pixelURL is:__ '.$pixelURL.'</p>';
// user decided to save a weblink for the pixel, so save it locally to server
copy($pixelURL, $target_path);

if i try to upload a file the error i get is:

pixelURL is: http://

uploadpixelURL is: coke.gif

destinationURL is: http://www.coca-cola.com/glp/d/index.html

There was an error uploading the file, please try again

Warning: copy(http://) [function.copy]: failed to open stream: Success in /home/www/promotion/pixelate/add.php on line 106

filename is:__

Warning: rename(,1_35f4a8d465e6e1edc05f3d8ab658c551.gif) [function.rename]: No such file or directory in /home/www/promotion/pixelate/add.php on line 109

pixelURL is:__ http://www.foo.com/img/pixelate/1_35f4a8d465e6e1edc05f3d8ab658c551.gif

02-28-2008, 09:55 PM
Looks like your server prevents the copy function from accessing external urls. You might have to use the CURL library: http://us2.php.net/curl

I haven't worked much with CURL so I can't give you an example.

02-29-2008, 01:44 AM
what if I used FTP functions.. would that help?