Jump to content

[SOLVED] upload


sniped22

Recommended Posts

On one page I have a file upload box where the user browses to the proper file, on the other it displays some info about the file.

 

How do I create a new html file implementing the uploaded file. I have it generate a random 10 digit number which I want to become the file's own page. So I generate the number, say 1234567890, how can I make that file in a php script, and then get the filename and use it in an object tag or img tag on 1234567890.html?

 

To make it clearer, I upload a.jpg, a random number 1111111111 is generated. I want the script to generate an html document with something like this:

 

<html>
<body>

<img src="../upload/a.jpg"> //a.jpg would have to be a variable such as $filename, and php would have to echo it somehow>
</body>
</html>

 

If any of you are familiar with imageshack.us, this is basically what I'm getting at.

 

 

Thanks for the help!

Link to comment
https://forums.phpfreaks.com/topic/40102-solved-upload/
Share on other sites

<?php

$random = $your_random_number
$new_page = "/home/your_content_dir/".$random.".html";

$somecontent = '<html>
<body>
<img src="../upload/'.$uploaded_file_name.'"> //a.jpg would have to be a variable such as $filename, and php would have to echo it somehow>
</body>
</html>';

    if (!$handle = fopen($new_page, 'w')) {
         echo "Cannot open file ($new_page)";
         exit;
    }

    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($new_page)";
        exit;
    }
    echo "Success, wrote ($somecontent) to file ($filename)";  
    fclose($handle);
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/40102-solved-upload/#findComment-194235
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.