Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-28-2008, 08:14 PM   PM User | #1
Bobafart
Regular Coder

 
Join Date: Dec 2006
Posts: 416
Thanks: 168
Thanked 1 Time in 1 Post
Bobafart is on a distinguished road
trying to save files to server via a form

i am trying to build a form where the user inputs an image from a weblink or an upload.

the form code is:

Code:
<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>
Code:
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:

Code:
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

Last edited by Bobafart; 02-28-2008 at 08:22 PM..
Bobafart is offline   Reply With Quote
Old 02-28-2008, 08:55 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 02-29-2008, 12:44 AM   PM User | #3
Bobafart
Regular Coder

 
Join Date: Dec 2006
Posts: 416
Thanks: 168
Thanked 1 Time in 1 Post
Bobafart is on a distinguished road
what if I used FTP functions.. would that help?
Bobafart is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:10 AM.


Advertisement
Log in to turn off these ads.