...

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



Bobafart
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>OR</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>
</form>




if(isset($_POST['uploadpixelURL'])){
// user decided to upload a pixel using var $uploadpixelURL
if($_FILES['uploadpixelURL']['type']=='image/jpeg'){
$fileext = '.jpg';
}else{
$fileext = '.gif';
}
$newname = $_SESSION[userid].'_'.md5(rand(1,1000)).$fileext;
if(move_uploaded_file($_FILES['uploadpixelURL']['tmp_name'], $target_path)) {
chmod($target_path,0777);
}else{
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>';
}else{
// 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

_Aerospace_Eng_
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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum