Jump to content

[SOLVED] Problem with image upload


derekbelcher

Recommended Posts

I am getting a "basename() expects parameter 1 to be string error.  Not sure what I am missing.  Help?

 

<?php

 

//This is the directory where images will be saved

$target = "/departments/athens/images/";

$target = $target . basename($_FILES['photo']);

 

 

// Connects to your Database

mysql_connect("-----") or die(mysql_error()) ;

mysql_select_db("p2r71184_photos") or die(mysql_error()) ;

 

//Writes the information to the database

mysql_query("INSERT INTO `athensPhoto` VALUES ('$photo')") ;

 

//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";

}

else {

 

//Gives and error if its not

echo "Sorry, there was a problem uploading your file.";

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/
Share on other sites

that was stupid :-) LOL. I changed uploadedfile to 'photo' and get same error.  I (as you can tell) am very new to php.  is there a better way to accomplish a photo upload.  Basically I want to allow users to upload up to 18 photos into the database.  is there a tutorial or idea someone could turn me on to. 

FILES:Array

(

    [photo] => Array

        (

            [name] => Untitled-2.jpg

            [type] => image/jpeg

            [tmp_name] => /tmp/phpFDLJZ5

            [error] => 0

            => 7574

        )

 

)

 

Does this make any since?  thanks for your help

That makes perfect sense when you have read the documentation for what you are attempting to do - http://us3.php.net/manual/en/features.file-upload.post-method.php

 

And the error is apparently (posting actual error messages help pin down where exactly the problem is in the code) being caused by this line of code -

 

$target = $target . basename($_FILES['photo']);

 

because $_FILES['photo'] is not the name of the uploaded file. $_FILES['photo']['name'] would be the variable that holds the name of the uploaded file.

Archived

This topic is now archived and is closed to further replies.

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