简体   繁体   中英

How can i upload a photo in a database with just holding on the the file name as a VARCHAR?

So i do not want to store a photo in the database because that takes too much memory storage. I want to hold the file name and then use that name to access the photo. how can i do this? here is my code so far but it does not work. In this code i am trying to make a folder in filezilla my target folder. right now move_upload_file() is returning false, what can i do to make it return true? I haven't implemented the database yet but when i do how would i be able to take the string of the file name and access the photo? My html:

<form method="post" action="BugReport.php" enctype="multipart/form-data">
                <div style = 'margin: 10px 225px 0px 225px;'><input type="hidden" name="size" value="350000">
                <input type="file" name="photo"> </div>
            </form>

My php:

//This is the directory where images will be saved
$target = "http://TheUrlIWantToUploadTo/Internship_Program/Edward/Project_5/Project_5/Output";
$target = $target . basename( $_FILES['photo']['name']);

$pic=($_FILES['photo']['name']);


//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['photo']['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.";
}

You cannot use a URL as a target for move_uploaded_file(). Think about it - you just processed an HTTP upload, and are trying to upload it to another URL, which would trigger another HTTP upload.

m_u_l() expects a LOCAL file path, never a url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM