This is very insecure, but if you're just trying to learn the basics of how some of this stuff works, then I hope that this is a helpful demonstration.
You can use file_put_contents
to write to files on disk. Be cognizant of operating system file permissions for the user account executing the script (web server). I use the /tmp
directory for this example because it usually exists on linux operating systems with global read/write permissions.
Make sure to use the FILE_APPEND
flag.
If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flag is set.
<?php
$file = '/tmp/some.file.name.html';
/*
$_GET['lastname'] is your "Link to image Page"
please change the `name` to something more appropriate
<input type="text" name="lastname" value="Image Page">
*/
if(isset($_GET['lastname'])){
$string_to_write = '
<div class="item">
<a href="'.$_GET['lastname'].'">
<img src="Image Source" height="268"/></a>
</div>
';
// if our file doesn't exist, then create it
if (!file_exists($file))
if(!touch($file))
trigger_error('ERROR: could not create file on disk', E_USER_ERROR);
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
if (!file_put_contents($file, $string_to_write, FILE_APPEND | LOCK_EX))
trigger_error('ERROR: could not write to file on disk', E_USER_ERROR);
// redirect to wherever
header('Location: /');
}
// print the file to screen
include($file);
?>
Add Your Image:
<form>
Raw Image File:
<input type="text" name="firstname" value="Raw Image">
<br>Link to image Page:
<input type="text" name="lastname" value="Image Page">
<br>
<input type="submit" value="Submit">
</form>
I'll leave the "Image Source" part for you. Uploading files is a different question.