Info about uploading and saving file

I am new to web development. So while learning, I see I can upload an image but not store it on the server. Is saving (using PHP script) images uploaded using the HTML page prohibited in infinityfree or is there a bug in the code?
So I wrote an HTML page where I can ask a user to upload an image. And I wish to save that image on the server. As I say again,I am the user and I am the admin of the site. So I am not doing this for any commercial or any other purpose other than learning. So just wished to confirm if its a bug or this is not possible in infinityfree.
Thank you very much for the answer!

You have to process the file with PHP and then save it to the server. This should help:

2 Likes

Many thanks for the reply! But is ‘file_uploads = On’ in php.ini? I see that infinityfree does not allow individual users to modify php.ini. Also, on other side, do you where I can see the configuration of php.ini which is set by infinityfree? Thanks!

You cannot view/edit the php.ini file. File uploads is turned on and you can save files to the server. That won’t be the problem. Could you share your PHP Code with us?

Yes, of course it is!

Even though we don’t allow file sharing sites, file upload functionality is still part of website administration for many kinds of sites.

The easiest way to check the PHP configuration is to create a new PHP file on your site (e.g. phpinfo.php) with the contents <?php phpinfo();, and then navigate to this file. This will show all the settings and variables available to that website.

4 Likes

Many thanks again for your reply.
I was following the code from the link you mentioned.

So I added a form tag in the HTML like:

<form action="/php/upload.php" method="post" enctype="multipart/form-data">
<p>Upload</p>
<input type="file" id="fileToUpload" name="fileToUpload">
<input type="submit" value="submit" name="submit">
</form>

In PHP, If I do:

<?php
$target_dir = "uploads/";
echo is_dir($target_dir); //prints "1". So I think this folder exists correctly and is read by php.
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
echo $_FILES["fileToUpload"]["name"]; // doesnot print anything
echo $_FILES["fileToUpload"]; // doesnot print anything
echo $_POST["fileToUpload"]; //doesn't print anything
echo "target file is";
echo $target_file; // this prints "../uploads/". So I think "$_FILES["fileToUpload"]["name"]" is not pointing to anything.
?>

Do you where I am going wrong or any extra check you would like me to run? As I said, I think $target_dir is fine but the $FILES[“fileToUpload”][“name”] is not pointing to the uploaded file.

Many thanks in advance for the reply!
This is how it looks inon webpage just before clicking on submit button:

This is the print output I get after clicking on the submit button:

As you see, “1” is for the target_dir exists check, Howevere, target file is still “uploads/” i.e. the uploaded file is not linked here (should have been “uploads/Annotation 2…10 - Copy.png”)

Please could you put your PHP code in a code block? (It makes it much easier to read)

Instead of trying to print the name, try printing this $_FILES["fileToUpload"]["tmp_name"].

Next thing, is the PHP Script throwing out any errors?

For some reason I see that it is now working which is weird for me as well since I literally didn’t change anything. I don’t know what the error was. Anyways thanks a lot for the help. Also I think “name” is fine. With “tmp_name” I was getting some other output.
Thanks a lot once again for your time and help!

Note that if you want the file to be uploaded to the server, you have to upload it using the tmp_name NOT the name. Ie:

move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], 'path/to/new/location');
4 Likes

Okay!I see! Thanks!

Many thanks for the reply! Also, Is there a way to check which libraries are installed on the server. I wished to convert a pdf to image but most of the php examples online use Imagemagic (or its derived form) library which I see in several Q and A on forum that this is not available on the server. Also, are you aware of any other library which could convert pdf to image format at backend using php script? Thanks in advance.

Create PHP file with this content <?php echo phpinfo() ?>, save it, and open it in your browser.

5 Likes

A quick Google search shows me some libraries but in the end they all use Imagick under the hood, which we indeed don’t provide on free hosting.

We provide the GD library for basic image manipulation, but I don’t think GD does PDF.

2 Likes

Okay! I see! Thanks a lot for the reply!
Do you/anyone know if the server has ghost script installed somewhere? “linux - Convert PDF to image in PHP without ImageMagick - Stack Overflow”?

Or is this possible in infinityfree

We don’t have Ghostscript, Imagemagick, libav-tools or anything else that could be used for media/document transcoding. We also have all command execution functions disabled in case we somehow did have a program that could be used for that.

So I’m afraid that this is just not possible.

4 Likes

I see! Thanks for the reply!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.