相关文章推荐
乐观的滑板  ·  vue3+ts ...·  1 月前    · 
阳光的胡萝卜  ·  flutter - Your ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to upload images to a server using ajax and php.

On client-side i hava the following code:

var reader = new FileReader();
reader.readAsDataURL(file, 'UTF-8');
reader.onload = function (event) {
    var result = event.target.result;
    $.ajax({    
    type: "POST",
    url: "url", 
    data: { 
       data: result, 
       name: file.name,
       mimeType: file.type

On server-side my code looks like the following:

 $path = 'somehow/'
 $fp = fopen( $path . $_POST['name'], 'w');
    $data = explode( ',', $_POST['data'] );
    fwrite($fp, base64_decode( $data[ 1 ] ));
    fclose($fp);
    chmod($path . $_POST['name'], 7777);
    list($width, $height) = getimagesize($path . $_POST['name']);

Now the method "getimagesize" always runs into an error "getimagesize(): Read error!"

Does anybody know, why this happens? When i look into the filesystem on the server the file 'FILENAME.JPG' exists ...

i'm not sure what you mean. i can find the picture on the server and with a ftp tool like filezilla i can download and open it again. – streetmaster86 Jan 9, 2019 at 21:59 what i mean is there is two cases for this error. If you said that you can open the picture it means that your url is not correct . Try to use absolute url maybe it will solve the problem. – Houssein Zouari Jan 10, 2019 at 9:05

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.