File upload problem

software development

#1

I’ve been searching both the forums and kbase, and still haven’t found a solution to the problem I’m having. I’m working on a php/mysql site that I did not originally code, and it was recently moved to Dreamhost from another hosting company, and even though none of the code in the pages in question have changed, the image upload is now not working on Dreamhost.

I’ve been banging my head against the wall trying to find the exact problem, and none of the solutions to the same problem posted in this forum are applicable to my situation.

The page is in an protected admin area on my client’s site, but basically the deal is that a entry is added in the section, that also includes a photo. The photo is uploaded to a temp directory, renamed and moved to another directory, while the entry is written to the db. The entry is writing to the db, but I get this error message everytime regarding the image upload:
Warning: copy(/home/litwin/jenniferlitwin.com/tmp/phpV8LOOl): failed to open stream: No such file or directory in /home/.ogies/
litwin/jenniferlitwin.com/admin/scripts/admin_press.php on line 120

The path to the temp directory is correct and both the temp directory and the final directory where the images are moved to are chmoded to 755. Can someone take a peek at the following code and tell me what I’m obviously overlooking?

Any help would be greatly appreciated. Thanks.

<?php include "../scripts/db.php"; $submitted = $_POST["submitted"]; $title = $_POST["title"]; $content = $_POST["content"]; $website = $_POST["website"]; $month = $_POST["month"]; $day = $_POST["day"]; $year = $_POST["year"]; $archive_date = $year . "-" . $month . "-" . $day; $active = $_POST["active"]; $action = $_GET["action"]; $ID = $_GET["ID"]; $tmp_upload_path = "/home/litwin/jenniferlitwin.com/tmp/"; $final_location="/graphics/press/"; $file_name1 = "press"; if ($action == "edit") { if ($ID == "") { $display_message = "Please choose a press item from the list below."; } else { if ($submitted == 1) { $exists_query = "SELECT press_ID FROM tbPress WHERE title = '$title'"; $exists_result = db_do_query($exists_query); $row_count = ($exists_result != 0) ? db_num_rows($exists_result) : 0; $exists_row = db_get_row($exists_result, $i); $edit_ID = $exists_row["press_ID"]; if (($row_count > 0) && ($ID != $edit_ID)) { $display_message = "A press item with that title already exists."; } else { $update_query = "UPDATE tbPress SET "; $update_query .= "title = '$title', "; $update_query .= "website = '$website', "; $update_query .= "content = '$content', "; $update_query .= "archive_date = '$archive_date', "; $update_query .= "active = $active "; $update_query .= "WHERE press_ID = $ID"; $update_result = db_do_query($update_query); $image_ID = $ID; $display_message = "Press item updated"; } } $select_query = "SELECT press_ID, title, website, content, DATE_FORMAT(archive_date,'%c') AS archive_month, DATE_FORMAT(archive_date,'%e') AS archive_day, DATE_FORMAT(archive_date,'%Y') AS archive_year, active FROM tbPress WHERE press_ID = $ID"; $select_result = db_do_query($select_query); $select_row = db_get_row($select_result,0); $press_ID = $select_row['press_ID']; $archive_month = $select_row['archive_month']; $archive_day = $select_row['archive_day']; $archive_year = $select_row['archive_year']; $title = $select_row['title']; $website = $select_row['website']; $content = $select_row['content']; $active = $select_row['active']; } } else if ($action == "delete") { if ($ID == "") { $display_message = "Please choose a press item from the list below."; } else { $delete_query = "DELETE FROM tbPress WHERE press_ID = $ID"; $delete_result = db_do_query($delete_query); $display_message = "Press item successfully deleted."; $final_full_path = $final_location . "press" . $ID . ".gif"; $return = @unlink($final_full_path); //var_dump($return); } } else if ($submitted == 1) { $exists_query = "SELECT press_ID FROM tbPress WHERE title = '$title'"; $exists_result = db_do_query($exists_query); $row_count = ($exists_result != 0) ? db_num_rows($exists_result) : 0; if ($row_count > 0) { $display_message = "A press item with that title already exists."; } else { $insert_query = "INSERT INTO tbPress(title,content,website,archive_date,active) "; $insert_query .= "VALUES('$title','$content','$website','$archive_date','$active')"; $insert_result = db_do_query($insert_query); $ID_query = "SELECT MAX(press_ID) AS press_ID FROM tbPress WHERE "; $ID_query .= "content = '$content'"; $ID_result = db_do_query($ID_query); $row = db_get_row($ID_result,0); $image_ID = $row['press_ID']; $display_message = "Press item added"; $content = ""; $title = ""; $website = ""; $archive_month = ""; $archive_day = ""; $archive_year = ""; $active = ""; } } if ($submitted == 1) { if (($action == "") || ($action == "edit")) { if ($_FILES['userfile1']['name'] != "") { $clients_file_name1 = $_FILES['userfile1']['tmp_name']; $temp_file_name1 = basename($clients_file_name1); if ($_FILES['userfile1']['type'] != "image/gif"){ $display_message = "Image must be a .gif"; } else { $new_file_name1 = $file_name1 . $image_ID . ".gif"; $temp_full_path1 = $tmp_upload_path . $temp_file_name1; $final_full_path1 = $final_location . $new_file_name1; if (!copy($temp_full_path1, $final_full_path1)) { $display_message = "Unable to upload image."; } } } } } $total_query = "SELECT title, press_ID, DATE_FORMAT(archive_date,'%c/%e/%Y') AS archives_date, active FROM tbPress ORDER BY archive_date desc"; $total_result = db_do_query($total_query); $total_row_count = ($total_result != 0) ? db_num_rows($total_result) : 0; $display_press = ""; $display_press .= ""; $display_press .= ""; $display_press .= ""; $display_press .= ""; $display_press .= ""; for ($i = 0; $i < $total_row_count; $i++) { $row = db_get_row($total_result, $i); $display_title = $row["title"]; $display_date = $row["archives_date"]; $display_active = $row["active"]; $display_ID = $row["press_ID"]; $display_press .= ""; $display_press .= ""; $display_press .= ""; $display_press .= ""; $display_press .= ""; } $display_press .= "
TitleDateActiveEditDelete
$display_title$display_date"; if ($display_active == 1) { $display_press .= "yes"; } else { $display_press .= "no"; } $display_press .= "EditDelete
"; ?>

#2

Line 16

$tmp_upload_path = “/home/litwin/jenniferlitwin.com/tmp/”;

You should just be able to put “”… When I’ve used script I haven’t needed to put any directory. I just use $_FILES[‘upload’][‘tmp_name’] instead of full directory.


#3

Thanks for the help, decswxaqz, but after changing it, I’m still getting the same error message and the image isn’t being uploaded at all.

Any other ideas about what could be causing the problem?

Thanks.


#4

Just noticed you/script is using copy. You should be using move_uploaded_file
This is the script I use

if(is_uploaded_file($_FILES[‘tmp_upload’][‘tmp_name’])){
if(!move_uploaded_file($_FILES[‘tmp_upload’][‘tmp_name’], $base_dir . $_FILES[‘tmp_upload’][‘name’])){
$file_upload = FALSE;
echo “File not uploaded

”;
}
else{
$file_upload = TRUE;
echo “File uploaded!

”;
}
}

Try chaning line 116 (copy line) to

if (!move_uploaded_file($_FILES[‘userfile1’][‘tmp_name’], $final_full_path1)) {


#5

Changing that line did the trick. Thank you so much for your help! You rock \m/


#6

^__^; aww shucks :slight_smile:
Glad it’s working.