Author Topic: having issue with uploading and moving a file through php  (Read 2254 times)

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
having issue with uploading and moving a file through php
« on: March 26, 2009, 11:01:10 AM »
This script started out in the root folder for testing and functioned as it should. of course i didnt want it public so i moved it into a subfolder and incorporated it into the admin functions. It no longer works, and i have tried every variation of the target folder path from relative to absolute and it refuses to work. All the data is written to the database of course, but the photo is not being uploaded to the /images/_fugitives folder. The target folder is the same as it has always been, and permissions are not an issue.

Micah and I went over it several times yesterday and cant seem to figure it out. I have enabled the error reporting and the issue seems to be with the move function.  None of the variable names have changed, but maybe the issue comes from the photo variable? or the pic variable? No idea.

Quote
Warning: move_uploaded_file(images/_fugitives/PINK.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/28/d279728753/htdocs/html2/_admin/process_fugitiveadd.php on line 45

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpEKWfMK' to 'images/_fugitives/PINK.jpg' in /homepages/28/d279728753/htdocs/html2/_admin/process_fugitiveadd.php on line 45
Sorry, there was a problem uploading your file.

Code: [Select]
<?php 
include '../includes/db_connect.php';

ini_set('display_errors''1');
error_reporting(E_ALL);

//This is the directory where images will be saved  
$target "/images/_fugitives/"
$target $target basename$_FILES['photo']['name']); 

//This gets all the other information from the form 
$fname mysql_real_escape_string($_POST['fname']);  
$mname mysql_real_escape_string($_POST['mname']);
$lname mysql_real_escape_string($_POST['lname']);
$alias mysql_real_escape_string($_POST['alias']);
$dob mysql_real_escape_string($_POST['dob']);
$pob mysql_real_escape_string($_POST['pob']);
$race mysql_real_escape_string($_POST['race']);
$lka mysql_real_escape_string($_POST['lka']);
$possible_locations mysql_real_escape_string($_POST['possible_locations']);
$assoc mysql_real_escape_string($_POST['assoc']);
$height mysql_real_escape_string($_POST['height']);
$weight mysql_real_escape_string($_POST['weight']);
$eye mysql_real_escape_string($_POST['eye']);
$hair mysql_real_escape_string($_POST['hair']);
$physical mysql_real_escape_string($_POST['physical']);
$city mysql_real_escape_string($_POST['city']);
$state mysql_real_escape_string($_POST['state']);
$offense mysql_real_escape_string($_POST['offense']);
$company mysql_real_escape_string($_POST['company']);
$pic=($_FILES['photo']['name']); 

//Writes the information to the database 
mysql_query("INSERT INTO fugitive (fname, mname, lname, alias, dob,
pob, race, height, weight, eye, hair,
city, state, offense, company, lka, possible_locations, 
assoc, physical, photo) 
VALUES ('
$fname', '$mname', '$lname', '$alias', '$dob',
'
$pob', '$race', '$height', '$weight', '$eye',
'
$hair', '$city', '$state', '$offense', '$company',
'
$lka', '$possible_locations', '$assoc', '$physical',
'
$pic')");

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 


//Tells you if its all ok 
echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"
echo 
'<br /><br /><br />';
echo 
'<a href="admin_addfugitive.php">Add Another</a>';

else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."
echo 
'<br /><br /><br />';
echo 
'<a href="admin_addfugitive.php">Go Back</a>';

?>

hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: having issue with uploading and moving a file through php
« Reply #1 on: March 26, 2009, 11:22:25 AM »
Just for giggles i tried the server path and got this error (the file was not uploaded)

Code: [Select]
$target = "/homepages/28/d279728753/htdocs/images/_fugitives";

Quote
Notice: Undefined index: uploadedfile in /homepages/28/d279728753/htdocs/html2/_admin/process_fugitiveadd.php on line 49
The file has been uploaded, and your information has been added to the directory


Add Another
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: having issue with uploading and moving a file through php
« Reply #2 on: March 26, 2009, 11:26:43 AM »
Try adding in some basic error checking...

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: having issue with uploading and moving a file through php
« Reply #3 on: March 26, 2009, 11:27:27 AM »
i have it

Code: [Select]
ini_set('display_errors', '1');
error_reporting(E_ALL);

hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: having issue with uploading and moving a file through php
« Reply #4 on: March 26, 2009, 05:30:18 PM »
The variables are passing accuratly, the target directory is accurate, yet it fails. I checked the permissions again and both the images directory and all sub directories are 777. I even tried doing it without $target by putting the directory right into the move function, nadda. I'm pulling my hair out i really dont understand the hold up. If it wasnt working the other day i would email the host. Is it possible they changed something on me?
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: having issue with uploading and moving a file through php
« Reply #5 on: March 26, 2009, 10:30:12 PM »
Error reporting is not the same as error checking.  You need to check $_FILES[...]['error'].

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: having issue with uploading and moving a file through php
« Reply #6 on: March 26, 2009, 10:39:09 PM »
i'll check it out in the AM. thanks mike
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: having issue with uploading and moving a file through php
« Reply #7 on: March 27, 2009, 08:55:14 AM »
ok i googled what you gave me and found a few examples using the same switch condition so i tried it. they were using 'uploadedfile' in the switch but that was telling me undefined index so i changed it to photo, and it results in the same two errors that i posted above.

Code: [Select]
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
echo '<br /><br /><br />';
echo '<a href="admin_addfugitive.php">Add Another</a>';
}
else {

switch ($_FILES['photo'] ['error'])
 {  case 1:
           print '<p> The file is bigger than this PHP installation allows</p>';
           break;
    case 2:
           print '<p> The file is bigger than this form allows</p>';
           break;
    case 3:
           print '<p> Only part of the file was uploaded</p>';
           break;
    case 4:
           print '<p> No file was uploaded</p>';
           break;
 }
}
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?