
- You are not logged in. | Login
November 17, 2006 7:02 am
- stp2233
- Member


return link to uploaded image
Hi, i've got this PHP image upload script, all I want to do with it now is return the full URL of the image to the user once the image has been uploaded. I know this should be simple so please excuse my ignorance;
<?php
$target_path = "uploads/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo '<p><font size="2pt"><strong>You may now register the image to the database</strong></font>
</p>';
} else{
echo '<p><strong>There was an error uploading the file, please try again!</p></strong>';
}
?>Any help appreciated.
November 23, 2006 12:50 pm
- senjor_itc
- Member


Re: return link to uploaded image
Hi, there is a solution:
<?php
$target_path = "uploads/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br/ >";
echo "Please, use the following link to dowload the file: <a href='" . $_SERVER['HTTP_HOST'] . 'uploads/' . basename( $_FILES['uploadedfile']['name']) . "'>".basename( $_FILES['uploadedfile']['name']) . '</a>';
echo '<p><font size="2pt"><strong>You may now register the image to the database</strong></font>
</p>';
} else{
echo '<p><strong>There was an error uploading the file, please try again!</p></strong>';
}
?>Thanks!


