PHP move_uploaded_file is Not uploading Images whe

2020-02-07 06:42发布

My Following code is working fine when I set

$target = "size_images/14_20131216231522_cashew.jpg";

But Not Working in Actual php Code when full web address path is given though 777 Unix access is granted to system.

I am trying upload an image from SubDomain to Main Domain, So i need to give Full Path.

Page: http://subdomain.examples.com/

Code:

$target = "http://examples.com/size_images/14_20131216231522_cashew.jpg";
move_uploaded_file($_FILES["item_image"]["tmp_name"],$target);

For your reference, following are values of above code line...

echo $_FILES["item_image"]["tmp_name"]; --> "/tmp/php6RNC28"

echo $target --> "http://examples.com/size_images/14_20131216231522_cashew.jpg"

Even tried with relative path instead of http, No luck : /home/direc/www/size_images

No use of placing error code. its not returning any error.

error_reporting(E_ERROR | E_PARSE);

标签: php html unix
4条回答
对你真心纯属浪费
2楼-- · 2020-02-07 07:22

It has to be a relative path.. absolute path would not work.

Also make sure that you know the difference between "/" and "./" But I would strongly recommend to either use configuration variables(in case of framework) OR constants to store file path.

Former point to root and later point to current directory..

查看更多
forever°为你锁心
3楼-- · 2020-02-07 07:30

Try using:

$target = $_SERVER['DOCUMENT_ROOT']."/size_images/14_20131216231522_cashew.jpg";

If you want to upload from subdomain.mydomain.com to mydomain.com simply put the upload script on mydomain.com and then use a relative path.

查看更多
狗以群分
4楼-- · 2020-02-07 07:38

Try this, You need to use only relative path instead of domain path. Domain path doesn't work

$target = "size_images/14_20131216231522_cashew.jpg";
move_uploaded_file($_FILES["item_image"]["tmp_name"],$target);

instead of ,

$target = "http://examples.com/size_images/14_20131216231522_cashew.jpg";
move_uploaded_file($_FILES["item_image"]["tmp_name"],$target);

Send a file via POST with cURL and PHP Ref: http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/

查看更多
放我归山
5楼-- · 2020-02-07 07:38

You are misunderstanding how move-uploaded-file() works. It is similar to "File Save", namely you have to tell the PHP script a locally-writeable directory and file name where the file goes.

You mention you're trying to go from "subdomain" to "main domain"... if these two web urls are hosted on the same machine, this will be possible, you will just choose the directory that has the files for the "main domain" site.

查看更多
登录 后发表回答