Mlaaa Posted January 9, 2017 Share Posted January 9, 2017 Hi As title say i have problem with image uploading. I don't get any error but image don't wanna to upload. Folder have permision 755. Here is a script : error_reporting(E_ALL); include 'header.php'; echo '<h2>Add image</h2>'; $target_dir = '../images/'; // Check if image file is a actual image or fake image if(isset($_POST['submit'])) { if(!empty($_FILE['fileToUpload'])) { $target_file = $target_dir . basename($_FILES['fileToUpload']['name']); $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); $check = getimagesize($_FILES['fileToUpload']['tmp_name']); if($check !== false) { // Check if file already exists if (file_exists($target_file)) { $error = '<p class="fail">Sorry, file already exists.</p>'; } else { if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) { $error = '<p class="success">The file '. basename( $_FILES['fileToUpload']['name']). ' has been uploaded.</p>'; } else { $error = '<p class="fail">Sorry, there was an error uploading your file.</p>'; } } } else { $error = '<p class="fail">File is not an image.</p>'; } } else { $error = '<p class="fail">Please select image.</p>'; } } And form html : <?php if(!empty($error)) { echo $error; } ?> <form action="" method="post" enctype="multipart/form-data"> <fieldset> <legend></legend> <p> <label for="file">Filename : </label> <input type="file" name="fileToUpload" id="file"> </p> <p><input type="submit" name="submit" value="Save"></p> </fieldset> </form> Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted January 9, 2017 Solution Share Posted January 9, 2017 $_FILES Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.