Jump to content

Basic php photo post and upload


jason360
Go to solution Solved by requinix,

Recommended Posts

Hey Guys,

 

Just stuck on this php form to upload.  I am trying to post a photo to the upload script.  For some reason it seems that only the photo's filename is being passed on from the form to the upload script, but not the actual photo.

 

Any help is much appreciated.

 

My code:

 

Form page:

<?php 

include("image_upload_script.php");




?>
        
<form enctype="multipart/form-data" class="clearfix" action="" method="post">
						<?php
                            
                            if($_SESSION['msg']['login-err'])
                            {
                                echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
                                unset($_SESSION['msg']['login-err']);
                            }
                        ?>
Choose your file here:
<input name="uploaded_file" type="file"/><br /><br />
<input type="submit" name="submit" value="Upload It" class="" />
</form>

Upload script:

<?php
session_start();
$pid ='1000';
if($_POST['submit']=='Upload It')
{

// Access the $_FILES global variable for this specific file being uploaded
// and create local PHP variables from the $_FILES array of information
$fileName = $_POST["uploaded_file"]["name"]; // The file name
$fileTmpLoc = $_POST["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_POST["uploaded_file"]["type"]; // The type of file it is
$fileSize = $_POST["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg = $_POST["uploaded_file"]["error"]; // 0 for false... and 1 for true
$kaboom = explode(".", $fileName); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension
$fileName = $pid.".".$fileExt; //rename

// Image handling after this, cut out for simplicity --------------------------------------------------

}


?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.