0

Hello i have a problem with my script for uploading a photo. The name it is stored in the database (123.jpg) but the photo doesnt go to folder i ask it to go
Here is my script

<form id="imageform" method="post" enctype="multipart/form-data" action='<?php echo $base_url; ?>press_image_ajax.php'> <span id='addphoto'><?php echo $lang['AddAPicture'];?>:</span> <input type="file" name="photopress" id="photopress" /> </form>

and the press_image_ajax.php

<?php
$target_dir = "http://localhost/Last/uploads/";
$target_file = $target_dir . basename($_FILES["photopress"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);


// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}

if (move_uploaded_file($_FILES["photopress"]["tmp_name"], $target_file)) 
{
    echo "The file ". basename( $_FILES["photopress"]["name"]). " has been uploaded.";
} 
else 
{
    echo "Sorry, there was an error uploading your file.";
}

?> 
2
Contributors
1
Reply
12
Views
1 Year
Discussion Span
Last Post by diafol
0

Do you get an error msg? Please try to explain fully when relating to code. Is the data reaching the press_image_ajax.php file at all? You mention that the filename is being stored in the DB - can't see any code for that. Is it in a different file? It should only be written tot he DB if the upload to the destination is a success - otherwise you get crap.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.