Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    what if I used FTP functions.. would that help?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •