Reputation: 11
I'm a novice to code in general but I'm trying to learn some things in my last summer before college. So far I have this much code that uploads the file to the server then displays it back within the upload.php.
How can I make it so that it generates a new link or html page with the uploaded image on it? I've looked up some possible solutions and I was thinking something along the lines of a html template that could be used for each image's individual page.
this is my upload.php I use in conjunction with an index.html form to upload the image and a description within a text file.
// code to save uploaded file
//finds extension to append later
$ext = pathinfo($_FILES['fn']['name'], PATHINFO_EXTENSION);
//creates timestamp for naming
$ran= time(). ".";
echo "<html><body>Upload Success<pre>";
/*echo var_dump($_FILES);
echo var_dump($_POST);
echo "size = ". $_FILES['fn']['size'];*/
echo "\n\n";
$picDir = "pics/" .$ran.$ext;
//saving to description text file
$dt = $_POST['ds'];
$dn= "descriptions/".$ran."txt" ;
$fh = fopen($dn, 'w') or die("can't open file");
$strData = "$dt";
fwrite($fh, $strData);
fclose($fh);
//close writing to text
//saving picture locally
move_uploaded_file($_FILES['fn']['tmp_name'], $picDir);
echo "<img src=$picDir width='800'>";
echo"\n\n";
echo "$dt";
echo "</body></html>";
?>
Upvotes: 1
Views: 85
Reputation: 8312
You can use a php header to redirect the browser to a page with the new image
i.e.
header("Location: http://www.example.com/viewImage.php?file={$picDir}/{$picName}");
Of course sanitize the file
variable in this case so that people aren't able to download any file they wish from your server
Upvotes: 1