Hi, I would like to create a simple way for people to send me photos via a webpage. I have tried a script which I have placed in my cgi-bin called upload.pl
The page in question is at www.beermattonline.co.uk/pink/contact_pets.html
It doesn't seem to work. Would anyone be able to help me out?
Thanks in advance, Matt.
Solved! Go to Solution.
Check that the target path is correct... save the following to a file, upload it to your target directory and open it in a browser. This will show the correct path name for that directory (it may be /webpages2 rather than /webpages)
<?php echo dirname(__FILE__); ?>
I think you also need to change the following line on your form:
<INPUT TYPE="FILE" NAME="file">
to:
<input name="uploaded" type="file">
If it is still failing, try running the uploader.php from a normal directory rather than from cgi-bin.
Here is a php version that is known to work. Save this as uploader.php or something similar and point your form action to this:
Change the target path to wherever you want the files to save to.
<?php $target = "/services/webpages/b/e/beermattonline.co.uk/public/uploads/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?>
Hi Dave. Thanks for your help. That still doesn't seem to work. Here is what I have on my page followed by the php version... I have changed the permission for the php file to 755. Any other suggestions?
Thanks again, Matt.
"<FORM ENCTYPE="multipart/form-data" ACTION="/cgi-bin/uploader.php" METHOD="POST"><p class="contact">please select a file to upload </p><INPUT TYPE="FILE" NAME="file"><p><INPUT TYPE="submit"></FORM>"
<?php $target = "/services/webpages/b/e/beermattonline.co.uk/public/pink/pet_photos/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";} else {echo "Sorry, there was a problem uploading your file.";}?>
Check that the target path is correct... save the following to a file, upload it to your target directory and open it in a browser. This will show the correct path name for that directory (it may be /webpages2 rather than /webpages)
<?php echo dirname(__FILE__); ?>
I think you also need to change the following line on your form:
<INPUT TYPE="FILE" NAME="file">
to:
<input name="uploaded" type="file">
If it is still failing, try running the uploader.php from a normal directory rather than from cgi-bin.
Many thanks. That seems to work. For reference I am not sure if all three steps were necessary but moving the uploader.php file to the root folder did the trick. I am going to look for a way to include an email address with the uploaded file and to give the visitor a way to return to a page on the site after upload. At least I know that it will work now.
Many thanks Dave. Kudos.
Matt.